package com.example.boot_easy.controller;

import com.example.boot_easy.pojo.Account;
import com.example.boot_easy.service.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/account")
@CrossOrigin
public class AccountController {
    private static final Logger logger = LoggerFactory.getLogger(AccountController.class);

    @Resource
    private AccountService accountService;

    @GetMapping("/hello")
    public String hello(String name,@RequestParam("gphone") String phone){
        return "hello"+name+phone;
    }

    @RequestMapping("/insert")
    public String insert(Account account){

        accountService.addAccount(account);
        return "success";
    }

    @RequestMapping("/delete")
    public String deleteById(Integer id){
        accountService.deleteById(id);
        return "success";
    }


    @RequestMapping("/update")
    public String updateById(Account account){
        logger.info("account=》"+account);
        accountService.updateById(account);
        return "success";
    }

    @RequestMapping("/query")
    public List<Account> query( ){
        logger.info("查询账户表开始");
        return accountService.query();
//        return "success";
    }


}
